package com.mop.app.common;

/**
 * 页面响应类
 *
 * @author fanmanfu
 * @version 1.0.0 初始化
 * @date 2018-06-08 11:30:44
 * Copyright 本内容仅限于杭州阿拉丁信息科技股份有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */

public class ResponseDo {


    private Boolean isSuccess;

    private String msg;

    private Object data;

    private String status;

    private final static String SUCCESS_CODE = "0000";
    private final static String ERROR_CODE = "9999";

    public static ResponseDo SUCCESS(String msg, Object data) {
        ResponseDo responseDo = new ResponseDo();
        responseDo.setData(data);
        responseDo.setMsg(msg);
        responseDo.setIsSuccess(true);
        responseDo.setStatus(SUCCESS_CODE);
        return responseDo;
    }

    public static ResponseDo SUCCESS(Object data) {
        return SUCCESS("操作成功", data);
    }

    public static ResponseDo SUCCESS() {
        return SUCCESS(null);
    }

    public static ResponseDo ERROR(Exception e) {
        ResponseDo responseDo = new ResponseDo();
        responseDo.setMsg(e.getMessage());
        responseDo.setIsSuccess(false);
        responseDo.setStatus(ERROR_CODE);
        return responseDo;
    }

    public static ResponseDo ERROR(String msg, String code) {
        ResponseDo responseDo = new ResponseDo();
        responseDo.setIsSuccess(false);
        responseDo.setStatus(code);
        responseDo.setMsg(msg);
        return responseDo;
    }

    public static ResponseDo ERROR() {
        return ERROR("系统开小差了");
    }

    public static ResponseDo ERROR(String msg) {
        return ERROR(msg, ERROR_CODE);
    }

    public Boolean getIsSuccess() {
        return isSuccess;
    }

    public void setIsSuccess(Boolean success) {
        isSuccess = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}
